package com.huiyeji.dynamic.core;

import com.huiyeji.sort.Matchable;
import com.huiyeji.sort.Order;
import com.huiyeji.sort.Sortable;
import com.huiyeji.sort.utils.OrderUtil;

import java.lang.reflect.Method;

public class MethodBody implements Matchable<MethodRequest>, Sortable {

    private final int order;

    private final Method method;

    private final String name;

    public MethodBody(String name, Method method) {
        this.name = name;
        this.method = method;
        if (method.isAnnotationPresent(Order.class)){
            this.order = method.getAnnotation(Order.class).value();
        } else {
            this.order = -1;
        }
    }

    public Method getMethod() {
        return method;
    }

    @Override
    public MethodRequest ruleInitialize() {
        return new MethodRequest(name,method.getParameterTypes());
    }

    @Override
    public int getOrder() {
        return order;
    }
}
